package com.ck.ck_back.controller;

import com.ck.ck_back.pojo.Result;
import com.ck.ck_back.service.likecommentservice;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/likecomment")
public class LikeCommentController {
    @Resource
    private likecommentservice  likecommentserviceimpl;

    @PostMapping("/like")
    public Object insert(int likedCommentId, String likedPostId){
        likecommentserviceimpl.saveLiked2Redis(likedCommentId,likedPostId);
        return Result.success();
    }

    @PostMapping("/dislike")
    public Object no(int likedCommentId, String likedPostId){
        likecommentserviceimpl.unlikeFromRedis(likedCommentId,likedPostId);
        return Result.success();
    }

    @PostMapping("/get")
    public Object getall(int likedCommentId, String likedPostId){
        int result= likecommentserviceimpl.getstate(likedCommentId,likedPostId);
        if (result == 1||result ==0){
            return Result.success(result);
        }else {
            return Result.failure("参数错误");
        }
    }

}
